<template>
  <ElementDialog ref="dialog" embed :visible="visible" height="500px" :title="title ? title : '项目课题'">
    <PageableTable
      ref="table"
      :multiple="multiple"
      :api="getPage"
      :disabled-row-keys="disabledRowKeys"
      click-row-select
      payload-style="body"
      hide-on-single-page>
      <TableColumn label="课题名称" prop="name" />
      <TableColumn label="承担单位" prop="undertakingUnit" />
      <TableColumn label="负责人" prop="masterName" />
      <TableColumn label="总经费 (万元)" prop="funds" />
      <TableColumn label="所属项目名称" prop="projectName" />
      <TableColumn label="备注" prop="remark" />
    </PageableTable>
    <template #footer>
      <ElButton size="mini" type="primary" @click="confirm">确定</ElButton>
      <ElButton size="mini" @click="close">取消</ElButton>
    </template>
  </ElementDialog>
</template>

<script>
  import { getPage } from './api'

  export default {
    name: 'ProjectTopicsDialog',
    props: {
      visible: Boolean,
      multiple: Boolean,
      title: String,
      projectId: String,
      disabledRowKeys: Array
    },
    methods: {
      getPage(data) {
        data.example.projectId = this.projectId
        return getPage(data)
      },
      close() {
        this.$refs.dialog.hide()
      },
      confirm() {
        if (this.multiple) {
          this.$emit('confirm', this.$refs.table.selectionRow)
        } else {
          this.$emit('confirm', this.$refs.table.currentRow)
        }
        this.close()
      }
    }
  }
</script>
